package com.ruoyi.project.remake.service.impl;

import java.util.List;

import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import com.ruoyi.project.remake.mapper.TRemakeMapper;
import com.ruoyi.project.remake.domain.TRemake;
import com.ruoyi.project.remake.service.ITRemakeService;

/**
 * 翻拍程序用户管理Service业务层处理
 *
 * @author 孙山伟
 * @date 2020-12-13
 */
@Service
public class TRemakeServiceImpl implements ITRemakeService
{
    @Autowired
    private TRemakeMapper tRemakeMapper;

    /**
     * 查询翻拍程序用户管理
     *
     * @param id 翻拍程序用户管理ID
     * @return 翻拍程序用户管理
     */
    @Override
    public TRemake selectTRemakeById(Long id)
    {
        return tRemakeMapper.selectTRemakeById(id);
    }

    /**
     * 查询翻拍程序用户管理列表
     *
     * @param tRemake 翻拍程序用户管理
     * @return 翻拍程序用户管理
     */
    @Override
    public List<TRemake> selectTRemakeList(TRemake tRemake)
    {
        return tRemakeMapper.selectTRemakeList(tRemake);
    }

    /**
     * 新增翻拍程序用户管理
     *
     * @param tRemake 翻拍程序用户管理
     * @return 结果
     */
    @Override
    public int insertTRemake(TRemake tRemake)
    {
        return tRemakeMapper.insertTRemake(tRemake);
    }

    /**
     * 修改翻拍程序用户管理
     *
     * @param tRemake 翻拍程序用户管理
     * @return 结果
     */
    @Override
    public int updateTRemake(TRemake tRemake)
    {
        tRemake.setPassword(SecurityUtils.encryptPassword(tRemake.getPassword()));
        return tRemakeMapper.updateTRemake(tRemake);
    }

    /**
     * 批量删除翻拍程序用户管理
     *
     * @param ids 需要删除的翻拍程序用户管理ID
     * @return 结果
     */
    @Override
    public int deleteTRemakeByIds(Long[] ids)
    {
        return tRemakeMapper.deleteTRemakeByIds(ids);
    }

    /**
     * 删除翻拍程序用户管理信息
     *
     * @param id 翻拍程序用户管理ID
     * @return 结果
     */
    @Override
    public int deleteTRemakeById(Long id)
    {
        return tRemakeMapper.deleteTRemakeById(id);
    }

    @Override
    public void checkUserAllowed(TRemake tRemake) {
       boolean flag= SecurityUtils.getLoginUser().getUser().isAdmin();
       if(!flag){
           throw new CustomException("只允许超级管理员修改用户密码");
       }
    }

    @Override
    public int resetPwd(TRemake tRemake) {
        tRemakeMapper.updateTRemake(tRemake);
        return 1;
    }

    @Override
    public TRemake selectByUsername(String username) {
        TRemake tRemake=new TRemake();
        tRemake.setLoginName(username);
        List<TRemake> remakeList=tRemakeMapper.selectTRemakeList(tRemake);
        return remakeList.size()==0?null:tRemakeMapper.selectTRemakeList(tRemake).get(0);
    }





}
